package showcase;



import com.opensymphony.xwork2.ActionSupport;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;


public class JsonSample extends ActionSupport{

    private static final long serialVersionUID = -2223948287805083119L;
    private List<String> languageList;
    private List<ListValue> languageObjList;
    private Map<String, String> languageMap;

    public String execute() {

      languageList = new ArrayList<String>();
      languageObjList = new ArrayList<ListValue>();
      languageMap = new HashMap<String, String>();

      languageList.add("Java");
      languageList.add("PHP");
      languageList.add("C++");

      languageMap.put("J", "Java");
      languageMap.put("P", "PHP");
      languageMap.put("C", "C++");

      languageObjList.add(new ListValue("J", "Java"));
      languageObjList.add(new ListValue("P", "PHP"));
      languageObjList.add(new ListValue("C", "C++"));

      return SUCCESS;
    }

    public String getJSON(){
    	return execute();
    }

    public List<String> getLanguageList()
    {
      return languageList;
    }

    public Map<String, String> getLanguageMap()
    {
      return languageMap;
    }

    public List<ListValue> getLanguageObjList()
    {
      return languageObjList;
    }

    public class ListValue {
    private String myKey;
    private String myValue;

    public ListValue(String myKey, String myValue) {
      super();
      this.myKey = myKey;
      this.myValue = myValue;
    }

    public String getMyKey()
    {
      return myKey;
    }

    public void setMyKey(String myKey)
    {
      this.myKey = myKey;
    }

    public String getMyValue()
    {
      return myValue;
    }

    public void setMyValue(String myValue)
    {
      this.myValue = myValue;
    }
  }
}